﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Comod_WarehouseAdd : ATPages
{
    ZSql zs = new ZSql();
    Function f = new Function();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request["action"] == "add")
            {
                ClientScript.RegisterStartupScript(typeof(Page), "aa", "dispAdd()", true);
            }
            if (Request["action"] == "update")
            {
                ClientScript.RegisterStartupScript(typeof(Page), "aa", "dispAdd()", true);
            }

            if (!string.IsNullOrEmpty(Request["id"]))
            {
                initData();
            }
            Label1.Text = f.getModuleidAdd(Request["moduid"]);
            lblDate.Text = DateTime.Now.ToShortDateString();
            Label2.Text = "";
            lblName.Text = Server.UrlDecode(Request.Cookies["user"].Values["realname"]);
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {


        if (Request["action"] == "flag")
        {
            if (RadioButton1.Checked)
            {
                zs.Open("update CS_Warehouse set AuditState='已通过' where WarehouseId="+Request["id"]);
                Response.Write("<script>window.location='WarehouseManage.aspx?moduid=" + Request["moduid"] + "';</script>");
            }
            if (RadioButton2.Checked)
            {
                zs.Open("update CS_Warehouse set AuditState='未通过' where WarehouseId="+Request["id"]);
                Response.Write("<script>window.location='WarehouseManage.aspx?moduid=" + Request["moduid"] + "';</script>");
            }

        }
        else
        {
            if (string.IsNullOrEmpty(txtWareName.Text))
            {
               
                
                ClientScript.RegisterStartupScript(typeof(Page), "aa", "dispAdd()", true);
                return;
            }
        }




      


        if (Request["action"] == "update")
        {
            zs.Open("update CS_Warehouse set WarehouseName='" + Common.FormatParameter(txtWareName.Text) + "',WarehouseMan='" + Common.FormatParameter(txtName.Text) + "',Phone='" + Common.FormatParameter(txtPhone.Text) + "',Address='" + Common.FormatParameter(txtAddress.Text) + "',Content='" + Common.FormatParameter(txtContent.Text) + "',EditUserName='" + lblName.Text + "',EditDate='" + lblDate.Text + "',warebh='"+Common.FormatParameter(txtbh.Text)+"' where WarehouseId=" + Request["id"]);
        }

        if (Request["action"] == "add")
        { 
            zs.Open("select * from CS_Warehouse where WarehouseName='" + txtWareName.Text + "'");
        if (zs.m_table.Rows.Count > 0)
        {
            Label2.Text = "仓库名已存在";
            ClientScript.RegisterStartupScript(typeof(Page), "aa", "dispAdd()", true);
            return;
        }

            zs.Open("insert into CS_Warehouse (WarehouseName,WarehouseMan,Phone,Address,Content,EditUserName,AuditState,EditDate,warebh)values('" + Common.FormatParameter(txtWareName.Text) + "','" + Common.FormatParameter(txtName.Text) + "','" + Common.FormatParameter(txtPhone.Text) + "','" + Common.FormatParameter(txtAddress.Text) + "','" + Common.FormatParameter(txtContent.Text) + "','" + lblName.Text + "','未审核','" + lblDate.Text + "','"+Common.FormatParameter(txtbh.Text)+"')");
        }



        zs.Close();

        Response.Redirect("WarehouseManage.aspx?moduid=" + Request["moduid"]);
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Redirect("WarehouseManage.aspx?moduid=" + Request["moduid"]);
    }

    private void initData()
    {
        zs.Open("select * from CS_Warehouse where WarehouseId=" + Request["id"]);
        txtWareName.Text = zs.m_table.Rows[0]["WarehouseName"].ToString();
        txtName.Text = zs.m_table.Rows[0]["WarehouseMan"].ToString();
        txtPhone.Text = zs.m_table.Rows[0]["Phone"].ToString();
        txtAddress.Text = zs.m_table.Rows[0]["Address"].ToString();
        txtContent.Text = zs.m_table.Rows[0]["Content"].ToString();
        txtbh.Text = zs.m_table.Rows[0]["warebh"].ToString();
    }


}
